home *** CD-ROM | disk | FTP | other *** search
AMOS Source Code | 1992-02-26 | 3.2 KB | 124 lines |
- Dim _ARRAY$(10,1)
- For A=1 To 10
- Read _ARRAY$(A,0),_ARRAY$(A,1)
- Next
- Data "fred","blogs"
- Data "some","body"
- Data "some","bodyelse"
- Data "mr","bean"
- Data "super","man"
- '
- Data "spider","man"
- Data "another","insect man"
- Data "flyspray","man"
- Data "mighty","midget"
- Data "captain","marrow"
- '
- Print "Before...." : Print
- For A=1 To 10
- Print _ARRAY$(A,0),_ARRAY$(A,1)
- Next
- Print : Print "Press a key" : Wait Key
- QUICKSORT[10,1]
- Cls : Home
- Print "After...." : Print
- For A=1 To 10
- Print _ARRAY$(A,0),_ARRAY$(A,1)
- Next
- End
-
- Procedure QUICKSORT[NO,ST]
- Shared _ARRAY$()
- '
- 'NO = Maximum element of _ARRAY in the dimension it is to be sorted in
- 'ST = First element of _ARRAY to sort (usually 0 or 1)
- '
- '_ARRAY$() = The array to be sorted. Use Global replace to change it
- ' to your array.
- '
- 'Define NOA$(A) to be the key to sort on where A is the array row in the
- 'dimension it is to be sorted on
- '
- Def Fn NOA$(A)=_ARRAY$(A,0)+_ARRAY$(A,1)
- '
- 'QuickSort Procedure - Don't Change
- '
- ' Comp Test Off
- Reserve As Work 9,NO*4+10 : STACK=1
- Doke Start(9),ST : Doke Start(9)+2,NO
- While STACK>0
- Dec STACK
- S=Deek(Start(9)+STACK*4) : E=Deek(Start(9)+STACK*4+2)
- While S<E
- SPLIT=S : I=Int((S+E)/2)
- If Fn NOA$(I)< Fn NOA$(E)
- If Fn NOA$(I)< Fn NOA$(S)
- If Fn NOA$(S)< Fn NOA$(E)
- PIVOT=S
- Else
- PIVOT=E
- End If
- Else
- PIVOT=I
- End If
- Else
- If Fn NOA$(I)< Fn NOA$(S)
- PIVOT=I
- Else
- If Fn NOA$(S)< Fn NOA$(E)
- PIVOT=E
- Else
- PIVOT=S
- End If
- End If
- End If
- PIVOT$= Fn NOA$(PIVOT)
- If PIVOT>S
- '
- '****************************************************
- 'Modify this code to swap array elements PIVOT and S
- '
- Swap _ARRAY$(PIVOT,0),_ARRAY$(S,0)
- Swap _ARRAY$(PIVOT,1),_ARRAY$(S,1)
- '
- '****************************************************
- PIVOT=S
- End If
- '
- '
- For I=S+1 To E
- If Fn NOA$(I)<PIVOT$
- Inc SPLIT
- '
- '********************************************************
- 'MOdify this code to swap elements SPLIT & I
- '
- Swap _ARRAY$(I,0),_ARRAY$(SPLIT,0)
- Swap _ARRAY$(I,1),_ARRAY$(SPLIT,1)
- '
- '********************************************************
- End If
- Next
- '
- '
- '*********************************************************
- 'Modify this code to swap elements PIVOT & SPLIT
- '
- Swap _ARRAY$(PIVOT,0),_ARRAY$(SPLIT,0)
- Swap _ARRAY$(PIVOT,1),_ARRAY$(SPLIT,1)
- '
- '*********************************************************
- '
- Doke Start(9)+STACK*4+2,E
- Doke Start(9)+STACK*4,SPLIT+1
- Inc STACK
- E=SPLIT-1
- 'Comp Test
- I$=Inkey$ : SC=Scancode : Exit If SC=69,2
- Wend
- Wend
- '
- Erase 9
- F=Free
- ' Comp Test On
- End Proc